/*#################################################

Time | v1.1
Max Felker | max@bigroomstudios.com

Time (as in traveling) class

#################################################*/
var Time = Class.create({

	initialize: function() {},

	display: function(config) {
	
		if(this.executer) {
			this.executer.stop();
		}
		
		this.executer = new PeriodicalExecuter(function() {
			this.get(config)
		}.bind(this),1);

	},
	
	get: function(config) {

		this.format = config.format ? config.format : false;
		this.verbose = 	config.verbose ? config.verbose : false;
		this.container = config.container ? $(config.container) : false;

		// output unix time stamp
		if(this.format=="unix") {
		
			this.current = Math.round(+new Date()/1000);
			
		} else {
		
			// weekend array
			var weekday = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");


			// define time properties
			this.date = new Date();
			var day = this.date.getDay();
			this.day = weekday[day].toLowerCase();
			this.hours = this.date.getHours();
			this.tod = '';
		
			if(this.format=="12hour") {
				this.tod = 'am';
				if(this.hours > 12) {
					this.tod = 'pm';
					this.hours = this.hours-12;
				}
			}
		
	
			this.mins = this.date.getMinutes();
			this.secs = this.date.getSeconds();
	
			// check if the mins and seconds are < 10
			(this.mins<10) ? this.mins = "0" + this.mins : this.mins = this.mins;
			(this.secs<10) ? this.secs ="0" + this.secs :  this.secs = this.secs;
	
			this.current = this.hours+":"+this.mins+":"+this.secs;

			if(this.verbose) {
				this.current = this.day.capitalize()+" at "+this.current+" "+this.tod.toUpperCase();
			}
		
		}
		
		if(this.container) {
			this.container.update(this.current);
		} else {
			return this.current;
		}
		
	}

});
